package com.ldu.exam.controller;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ldu.exam.model.SubmitPaper;
import com.ldu.exam.model.TestQuestionModel;
import com.ldu.exam.service.SubmitService;

@RequestMapping("/Submit") 
@RestController
public class SubmitController 
{
	@Autowired SubmitService service;
	
	@GetMapping()
	public Page<SubmitPaper> findAll(@RequestParam(required=false) String name,
			@RequestParam(required=false) String accountId,
			@RequestParam String teacherId,
			@PageableDefault(size=20) Pageable page) 
	{
		return this.service.findAll(name,accountId,teacherId,page);
	}
	
	
	@PostMapping(value="/{accountId}")
	public Object submit(@PathVariable String accountId,@RequestParam String paperName,@RequestParam String classId,@RequestBody Set<TestQuestionModel> set)
	{
		return this.service.submit(accountId,paperName,classId,set);
	}
}
